/*
 Copyright (c) 2013 MeherTJ G. All rights reserved.
 License: LGPL for personnal study or free software.
 */

#pragma once

#include <ctime>
#include <cstdarg>
#include <cstdio>
#include <sstream>

#include "zen_macro.h"

#ifdef ZEN_OS_ANDROID
#include "android/log.h"
#endif

namespace Zen {

	inline void __LogPrint(int type, char const * fmt, va_list args)
	{
#ifdef ZEN_OS_ANDROID
		__android_log_vprint(type?ANDROID_LOG_ERROR:ANDROID_LOG_DEBUG, "ZEN_LOG", fmt, args);
#else
		std::string fmts;
		fmts.push_back(type?'I':'D');
		fmts.push_back(':');
		fmts.append(fmt);
		fmts.append("\n");
		vfprintf(stdout, fmts.c_str(), args);
		fflush(stdout);
#endif
	}
	inline void LogE(char const * fmt, ...)
	{
		va_list va;
		va_start(va, fmt);
		__LogPrint(1, fmt, va);
		va_end(va);
	}
	inline void LogD(char const * fmt, ...)
	{
#if ZEN_DEBUG
    va_list va;
		va_start(va, fmt);
		__LogPrint(0, fmt, va);
		va_end(va);
#endif
	}
}

#define ZenDebugLog(index) Zen::LogD("%s[%d]~%d", __FUNCTION__, __LINE__, (int)(index))


